<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    123123
    <p id="p">关闭</p>
    <script>
        var ws = new WebSocket("ws://localhost/ws/sa");  
        var p = document.getElementById('p')
        //连接打开时触发 
        ws.onopen = function(evt) {  
            console.log("Connection open ...");  
            ws.send("Hello WebSockets!");  
        };  
        //接收到消息时触发  
        ws.onmessage = function(evt) {  
            console.log("Received Message: " + evt.data);  
        };  
        //连接关闭时触发  
        ws.onclose = function(evt) {  
            console.log("Connection closed.");  
        };  
        p.onclick = function(){
            ws.close(1,'123') 
        }
        </script>
</body>
</html>